﻿namespace HySoft.Cash.DB
{
    using Huayou.Common.Database;
    using Huayou.Utils;
    using HySoft.Cash.BaseClass;
    using HySoft.Cash.Structure;
    using System;
    using System.Data;

    public class TinvoicelistDB : BaseDB
    {
        

        public TinvoicelistDB(DBOperate oper)
            : base(oper)
        {
        }

        public bool Add(TinvoicelistDT detail)
        {
            int num = 0;
            string strSql = string.Concat(new object[] { "INSERT INTO tInvoiceList (OrgSid,InvoiceDate,Principal,Interest,IsValid,ReceiveAmount,Note) VALUES (", detail.OrgSid, ",'", detail.InvoiceDate, "',", detail.Principal, ",", detail.Interest, ",", (int)detail.IsValid, ",", detail.ReceiveAmount, ",'", StringUtils.ToSQL(detail.Note), "')" });
            try
            {
                try
                {
                    num = base.ExecuteForInt(strSql);
                }
                catch (Exception exception)
                {
                    throw exception;
                }
            }
            finally
            {
            }
            return (num == 1);
        }

        public bool Delete(int Sid)
        {
            int num = 0;
            string strSql = "DELETE FROM tInvoiceList where (Sid=" + Sid + ")";
            try
            {
                try
                {
                    num = base.ExecuteForInt(strSql);
                }
                catch (Exception exception)
                {
                    throw exception;
                }
            }
            finally
            {
            }
            return (num == 1);
        }

        public bool Edit(TinvoicelistDT detail)
        {
            int num = 0;
            string strSql = string.Concat(new object[] { "UPDATE tInvoiceList set OrgSid=", detail.OrgSid, ",InvoiceDate='", detail.InvoiceDate, 
                "',IsValid=", (int)detail.IsValid, ",Note='", StringUtils.ToSQL(detail.Note), "', SendStatus="+ (int)detail.SendStatus +" where (Sid=", detail.Sid, ")" });
            //string strSql = string.Concat(new object[] { "UPDATE tInvoiceList set OrgSid=", detail.OrgSid, ",InvoiceDate='", detail.InvoiceDate, 
            //    "',InvoiceAmount=",detail.InvoiceAmount, ",IsValid=", (int)detail.IsValid, ",ReceiveAmount=", 
            //    detail.ReceiveAmount, ",Note='", StringUtils.ToSQL(detail.Note), "', SendStatus="+ (int)detail.SendStatus +" where (Sid=", detail.Sid, ")" });
            try
            {
                try
                {
                    num = base.ExecuteForInt(strSql);
                }
                catch (Exception exception)
                {
                    throw exception;
                }
            }
            finally
            {
            }
            return (num == 1);
        }

        public TinvoicelistDT Get(int Sid)
        {
            TinvoicelistDT tdt = new TinvoicelistDT();

            try
            {
                string strSql = string.Format("select {0} from tInvoiceList where Sid={1}", TinvoicelistDT.allFields, Sid);
                DataTable table = base.ExecuteForDataTable(strSql);
                DataRow row = null;
                if (table.Rows.Count >= 0)
                {
                    row = table.Rows[0];
                    tdt = TinvoicelistDT.ConvertFrom(row);
                }
            }
            catch (Exception exception)
            {
                throw exception;
            }

            return tdt;
        }

        public DataTable GetList()
        {
            DataTable table = null;
            try
            {
                try
                {
                    string strSql = string.Format("select {0} from tInvoiceList", TinvoicelistDT.allFields);
                    table = base.ExecuteForDataTable(strSql);
                }
                catch (Exception exception)
                {
                    throw exception;
                }
            }
            finally
            {
            }
            return table;
        }
    }
}

